home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 028a / arcutils.zip / UNARC.C < prev    next >
C/C++ Source or Header  |  1989-04-20  |  3KB  |  124 lines

  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include <dir.h>
  4. #include <stdlib.h>
  5.  
  6. main(argc,argv)
  7. int argc;
  8. char *argv[];
  9. {
  10.    char string[80],string2[80],string3[15],ext[20][5],method[20][50];
  11.    FILE *file;
  12.    int i,type,done,number=0;
  13.    struct ffblk ffblk;
  14.  
  15.    typedef struct file_stack FILES;
  16.    struct file_stack {              /* holds a directory listing */
  17.       char string[13];
  18.       FILES *next;
  19.    };
  20.  
  21.    FILES *head,*tail,*temp_hold;
  22.  
  23.  
  24.    printf("Universal Unarchiver\n");
  25.    printf("Ver (1.05)\nDave Harris  1:302/5\n\n");
  26.  
  27.    if (argc==1)
  28.       strcpy(string3,"*.*");
  29.    else
  30.       strcpy(string3,argv[1]);
  31.  
  32.    if (!strstr(string3,"."))
  33.       strcat(string3,".*");
  34.  
  35. /*************************************************************************/
  36. /* open the configuration file, look through path if necessary */
  37.  
  38.    file=fopen("unarc.cfg","r");
  39.    if (file==NULL) {                     /* ok, its not in the current */
  40.       int pathpos=0,dirpos;              /* directory so lets trudge through */
  41.       char path[200],directory[80];      /* the PATH */
  42.       strcpy(path,getenv("PATH"));       
  43.  
  44.       while (1) {
  45.          dirpos=0;
  46.          while (path[pathpos]!=';' && path[pathpos]!=NULL) {
  47.             directory[dirpos++]=path[pathpos++];
  48.          }
  49.          if (path[pathpos]==NULL) {        /* we have looked through the whole
  50.                                               PATH without success */
  51.             printf("Can't find UNARC.CFG\n");
  52.             exit(1);
  53.          }
  54.          pathpos++;     /* get us over the ; */
  55.  
  56.          if (directory[dirpos-1]!='\\')
  57.             directory[dirpos++]='\\';
  58.          directory[dirpos]=NULL;
  59.          strcat(directory,"unarc.cfg");
  60.          file=fopen(directory,"r");
  61.          if (file!=NULL)
  62.             break;
  63.          else
  64.             fclose(file);
  65.       }
  66.    }
  67. /**********************************************************************/
  68. /* parse the configuration file for the control info */
  69.  
  70.    while (fscanf(file,"%s",ext[number])!=EOF) {
  71.       type=0;
  72.       while (1) {
  73.          i=getc(file);
  74.          if (i=='\n' || i==EOF) {
  75.             method[number][type]=NULL;
  76.             number++;
  77.             break;
  78.          }
  79.          else
  80.             method[number][type++]=i;
  81.       }
  82.       strupr(ext[number]);
  83.    }
  84.  
  85. /********************************************************************/
  86. /* get all the file names and put them on the queue */
  87.  
  88.    done=findfirst(string3,&ffblk,0);
  89.    if (done)
  90.       exit(0);
  91.    head=(FILES*)malloc(sizeof(FILES));
  92.    strcpy(head->string,ffblk.ff_name);
  93.    head->next=NULL;
  94.    tail=head;
  95.    while (!done) {
  96.       done=findnext(&ffblk);
  97.       if (done)
  98.          break;
  99.       temp_hold=(FILES*)malloc(sizeof(FILES));
  100.       strcpy(temp_hold->string,ffblk.ff_name);
  101.       tail->next=temp_hold;
  102.       tail=temp_hold;
  103.       tail->next=NULL;
  104.    }
  105. /********************************************************************/
  106.  
  107.    while (head!=NULL)  {
  108.       strcpy(string,head->string);
  109.       for (i=0;i<=number;i++) {
  110.          if (strstr(string,ext[i])!=NULL) {
  111.             printf("Unarching %s\n",string);
  112.             sprintf(string2,method[i],string);
  113.             system(string2);
  114.             break;
  115.          }
  116.       }
  117.       temp_hold=head;
  118.       head=head->next;
  119.       free(temp_hold);          /* clean up behind */
  120.    }
  121.  
  122. }
  123.  
  124.